
/* GCSx
** SLIDER.H
**
** Numerical slider widget
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_SLIDER_H_
#define __GCSx_SLIDER_H_

class WSlider : public Widget {
protected:
    // Range and pixel length of slider
    int pixelLength;
    int rangeBegin;
    int rangeEnd;
    
    // Exact current value
    int currentValue;
    
    // Pixel position based on current value
    int pixelValue;
    
    // Currently dragging slider?
    int dragging;
    int draggingX;
    int draggingValue;
    
    // Linked?
    WNumberBox* linkedTo;
    
    enum {
        // Height and width of slider itself
        GUI_SLIDER_TABWIDTH = 10,
        GUI_SLIDER_TABHEIGHT = 20,
        
        // Height of slider track
        GUI_SLIDER_TRACKSIZE = 2,
        
        // Default length of slider track if not given
        GUI_SLIDER_TRACKLENGTH = 50,
    };

public:
    // Actual length may differ slightly from length given
    WSlider(int sId, int sBegin, int sEnd, int* sSetting, int sLength = -1);

    // Optionally link a slider to a numberbox, which should have the same range
    void linkTo(WNumberBox* linked);

    int event(int hasFocus, const SDL_Event* event);
    void load();
    void apply();
    void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);

    // Handles linkTo()
    virtual void siblingModified(Widget* modified);
    
    // Set or retrieve state
    int state() const;
    // ALL changes go through this function
    // 'fromLoad' is for internal use only
    int state(int newValue);
    int stateFromLoad(int newValue);
    
    // Set state based on a pixel location from 0 to pixelValue, inclusive
    // Returns actual state() value set (not the pixel value)
    int statePixel(int newPixel);
};

#endif

